<html>
<head><meta charset="utf-8"><title>Proposal: `#[repr(type_alias)]` · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Proposal.3A.20.60.23.5Brepr(type_alias).5D.60.html">Proposal: `#[repr(type_alias)]`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204326359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Proposal%3A%20%60%23%5Brepr%28type_alias%29%5D%60/near/204326359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Proposal.3A.20.60.23.5Brepr(type_alias).5D.60.html#204326359">(Jul 19 2020 at 01:31)</a>:</h4>
<p>Would it be possible to extend the <code>repr</code> attribute to allow not only the integer types but also to allow any type alias of an integer type?</p>



<a name="204326400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Proposal%3A%20%60%23%5Brepr%28type_alias%29%5D%60/near/204326400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Proposal.3A.20.60.23.5Brepr(type_alias).5D.60.html#204326400">(Jul 19 2020 at 01:32)</a>:</h4>
<p>What would the use case be?</p>



<a name="204327166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Proposal%3A%20%60%23%5Brepr%28type_alias%29%5D%60/near/204327166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Proposal.3A.20.60.23.5Brepr(type_alias).5D.60.html#204327166">(Jul 19 2020 at 01:55)</a>:</h4>
<p>Primarily that with FFI the size of a const is (generally) fixed but the sign-ness isn't always fixed because of platform C convention differences between Windows and Unix.</p>
<p>When making a rust <code>enum</code> that names however many values (so that users can be appropriately limited in the values they send to the C function) you sometimes want to write something <a href="https://github.com/Lokathor/beryllium/blob/cfdd6a3e14b0b71b5dda1718e1826d815d41e3fd/src/window/gl_window.rs#L125">like this</a>, where you're setting each enum variant to be some value defined in C.</p>
<p>However, as you'll note with the attributes there, what I'm <em>trying</em> to say is that the repr of that enum is "whatever the repr of <code>SDL_GLattr</code> is". This intent is completely missing from the source code though. You have to have specific extra knowledge about both the type of those const definitions being mapped, and <em>also</em> that the numeric type of the consts varies by platform, before the two cfg_attr entries make sense to the reader.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>